<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 患者信息
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.patientid" placeholder="患者ID" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-input v-model="query.hospitalid" placeholder="医院ID" class="handle-input mr10" @keyup.enter.native="handleSearch"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="el-button" icon="el-icon-delete" @click="handleReset">重置</el-button>
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column v-if="isShow" prop="id" label="ID" width="200" align="center" sortable></el-table-column>
                <el-table-column prop="patientid" label="患者ID" width="200" align="center"></el-table-column>
                <el-table-column prop="treattype" label="治疗类型" width="90" align="center"></el-table-column>
                <el-table-column prop="treatdate" label="治疗日期" width="150" align="center" sortable></el-table-column>
                <el-table-column prop="bodypart" label="治疗部位" width="210" align="center"></el-table-column>
                <el-table-column prop="intensity" label="刺激强度(%)" width="130" align="center" sortable></el-table-column>
                <el-table-column prop="threshold" label="刺激阈值(%)" width="130" align="center" sortable></el-table-column>
                <el-table-column prop="numall" label="总刺激个数" align="center" sortable></el-table-column>
                <el-table-column prop="numover" label="已刺激个数" align="center" sortable></el-table-column>
                <el-table-column prop="hospitalid" label="医院ID" align="center" width="180"></el-table-column>
                <el-table-column prop="hospitalsystemid" label="机器编号" align="center"></el-table-column>
                <el-table-column label="操作"  align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-view"
                                @click="handleView(scope.$index, scope.row)"
                        >查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageIndex"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="查看" :visible.sync="editVisible" width="40%" :before-close="editColse">
            <el-form ref="form" :model="editForm" label-width="100px" >
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="患者ID:" prop="patientid" >
                            <el-input disabled v-model="editForm.patientid" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="治疗类型:" prop="treattype" >
                            <el-input disabled v-model="editForm.treattype" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="治疗日期:" prop="treatdate" >
                            <el-input disabled v-model="editForm.treatdate" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="治疗部位:" prop="bodypart" >
                            <el-input disabled v-model="editForm.bodypart" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="刺激强度:" prop="intensity" >
                            <el-input disabled v-model="editForm.intensity + '%'" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="刺激阈值:" prop="threshold" >
                            <el-input disabled v-model="editForm.threshold + '%'" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="editForm.treattype == 'auto'">
                    <el-col :span="12">
                        <el-form-item label="刺激频率:" prop="frequency" >
                            <el-input disabled v-model="editForm.frequency" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="刺激个数:" prop="continuenum" >
                            <el-input disabled v-model="editForm.continuenum" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="editForm.treattype == 'auto'">
                    <el-col :span="12">
                        <el-form-item label="时间间隔:" prop="period" >
                            <el-input disabled v-model="editForm.period" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="重复次数:" prop="repeat" >
                            <el-input disabled v-model="editForm.repeat" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="editForm.treattype == 'manual'">
                    <el-col :span="12">
                        <el-form-item label="触发方式:" prop="triggerText" >
                            <el-input disabled v-model="editForm.triggerText" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="内触发延时:" prop="delayed" >
                            <el-input disabled v-model="editForm.delayed + 'ms'" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="总刺激个数:" prop="numall" >
                            <el-input disabled v-model="editForm.numall" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="已刺激个数:" prop="numover" >
                            <el-input disabled v-model="editForm.numover" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="医院ID:" prop="hospitalid" >
                            <el-input disabled v-model="editForm.hospitalid" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="上传时间:" prop="datauptime" >
                            <el-input disabled v-model="editForm.datauptime" style="width: 100%"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editColse">关闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import { getData,selectById } from '../../../api/jlc/jlcTreatrecord';
    export default {
        name: 'JlcTreaTrecord',
        data() {
            return {
                query: {
                    patientid: '',
                    hospitalid:'',
                    userAcct:localStorage.getItem('ms_userAcct'),
                    pageIndex: 1,
                    pageSize: 10
                },
                tableData: [],
                multipleSelection: [],
                editVisible: false,
                pageTotal: 0,
                editForm: {},
                idx: -1,
                id: -1,
                isShow:false,
            };
        },
        created() { //调用ajax获取页面初始化所需的数据
            this.getData();
        },
        methods: {
            // 获取后台数据
            getData() {
                getData(this.query).then(res => {
                    if (res.success == true){
                        this.tableData = res.data;
                        this.pageTotal = res.total;
                    } else {
                        this.$message.error("查询失败！");
                        this.tableData = [];
                        this.pageTotal = 0;
                    }
                });
            },
            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1);
                this.getData();
            },
            // 触发重置按钮
            handleReset() {
                this.query.patientid = "";
                this.query.hospitalid="";
                this.getData();
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val);
                this.getData();
            },
            handleView(index, row){
                this.idx = index;
                this.editForm = row;
                this.editVisible = true;
            },
            editColse() {//关闭编辑弹出框
                this.editVisible = false;
            }
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .mr10 {
        margin-right: 10px;
    }
</style>
